package main

import (
	"cloud-entropy-storage-system/volume/internal/config"
	"cloud-entropy-storage-system/volume/internal/server"
	"flag"
	"os"
	"os/signal"

	"github.com/zeromicro/go-zero/core/conf"
	"syscall"
)

var (
	configFile = flag.String("f", "etc/config.yaml", "the config file")
	cfg        config.Config
)

func main() {
	flag.Parse()
	conf.MustLoad(*configFile, &cfg)

	svr := server.NewServer(cfg)

	shutDown(svr)
}

func shutDown(svr *server.Server) {
	signals := make(chan os.Signal)
	signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
	sig := <-signals

	svr.Close()

	switch sig {
	case syscall.SIGINT:
		os.Exit(int(syscall.SIGINT))
	case syscall.SIGTERM:
		os.Exit(int(syscall.SIGTERM))
	}
}
